package com.demo.netty.demo01;

import com.demo.netty.demo01.handler.CatServerHandler;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.bytes.ByteArrayDecoder;
import io.netty.handler.codec.bytes.ByteArrayEncoder;

public class CatServerDemo {

    public static void main(String[] args) throws InterruptedException {
        ServerBootstrap serverBootstrap = new ServerBootstrap();
        NioEventLoopGroup boss = new NioEventLoopGroup(1);
        NioEventLoopGroup worker = new NioEventLoopGroup(3);
        serverBootstrap.group(boss, worker)
                .channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_BACKLOG, 100)
                .childHandler(new ChannelInitializer<Channel>() {
                    @Override
                    protected void initChannel(Channel ch) throws Exception {
                        ChannelPipeline pipeline = ch.pipeline();
                        pipeline.addLast(new CatServerHandler());
                    }
                });
        System.out.println("服务端初始化成功。。。。。");
        ChannelFuture future = serverBootstrap.bind(9999).sync();
        System.out.println("服务端future：" + future);
        future.channel().closeFuture().sync();
        //关闭连接池
        boss.shutdownGracefully();
        worker.shutdownGracefully();
    }
}
